import 'package:guochaoapp/model/cart_entity.dart';

cartEntityFromJson(CartEntity data, Map<String, dynamic> json) {
	if (json['success'] != null) {
		data.success = json['success'];
	}
	if (json['msg'] != null) {
		data.msg = json['msg'].toString();
	}
	if (json['code'] != null) {
		data.code = json['code'] is String
				? int.tryParse(json['code'])
				: json['code'].toInt();
	}
	if (json['data'] != null) {
		data.data = new List<CartData>();
		(json['data'] as List).forEach((v) {
			data.data.add(new CartData().fromJson(v));
		});
	}
	if (json['sign'] != null) {
		data.sign = json['sign'];
	}
	return data;
}

Map<String, dynamic> cartEntityToJson(CartEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['success'] = entity.success;
	data['msg'] = entity.msg;
	data['code'] = entity.code;
	if (entity.data != null) {
		data['data'] =  entity.data.map((v) => v.toJson()).toList();
	}
	data['sign'] = entity.sign;
	return data;
}

cartDataFromJson(CartData data, Map<String, dynamic> json) {
	if (json['categoryName'] != null) {
		data.categoryName = json['categoryName'].toString();
	}
	if (json['img'] != null) {
		data.img = json['img'].toString();
	}
	if (json['skuCount'] != null) {
		data.skuCount = json['skuCount'] is String
				? int.tryParse(json['skuCount'])
				: json['skuCount'].toInt();
	}
	if (json['skuNumCount'] != null) {
		data.skuNumCount = json['skuNumCount'] is String
				? int.tryParse(json['skuNumCount'])
				: json['skuNumCount'].toInt();
	}
	if (json['unit'] != null) {
		data.unit = json['unit'].toString();
	}
	if (json['itemList'] != null) {
		data.itemList = new List<CartDataItemList>();
		(json['itemList'] as List).forEach((v) {
			data.itemList.add(new CartDataItemList().fromJson(v));
		});
	}
	if (json['checked'] != null) {
		data.checked = json['checked'];
	}
	if (json['expand'] != null) {
		data.expand = json['expand'];
	}
	return data;
}

Map<String, dynamic> cartDataToJson(CartData entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['categoryName'] = entity.categoryName;
	data['img'] = entity.img;
	data['skuCount'] = entity.skuCount;
	data['skuNumCount'] = entity.skuNumCount;
	data['unit'] = entity.unit;
	if (entity.itemList != null) {
		data['itemList'] =  entity.itemList.map((v) => v.toJson()).toList();
	}
	data['checked'] = entity.checked;
	data['expand'] = entity.expand;
	return data;
}

cartDataItemListFromJson(CartDataItemList data, Map<String, dynamic> json) {
	if (json['skuId'] != null) {
		data.skuId = json['skuId'] is String
				? int.tryParse(json['skuId'])
				: json['skuId'].toInt();
	}
	if (json['spuId'] != null) {
		data.spuId = json['spuId'];
	}
	if (json['mallTitle'] != null) {
		data.mallTitle = json['mallTitle'].toString();
	}
	if (json['brandId'] != null) {
		data.brandId = json['brandId'] is String
				? int.tryParse(json['brandId'])
				: json['brandId'].toInt();
	}
	if (json['brandName'] != null) {
		data.brandName = json['brandName'].toString();
	}
	if (json['skuSpec'] != null) {
		data.skuSpec = json['skuSpec'].toString();
	}
	if (json['price'] != null) {
		data.price = json['price'] is String
				? double.tryParse(json['price'])
				: json['price'].toDouble();
	}
	if (json['num'] != null) {
		data.num = json['num'] is String
				? int.tryParse(json['num'])
				: json['num'].toInt();
	}
	if (json['stock'] != null) {
		data.stock = json['stock'] is String
				? int.tryParse(json['stock'])
				: json['stock'].toInt();
	}
	if (json['weight'] != null) {
		data.weight = json['weight'] is String
				? double.tryParse(json['weight'])
				: json['weight'].toDouble();
	}
	if (json['categoryName'] != null) {
		data.categoryName = json['categoryName'].toString();
	}
	if (json['unit'] != null) {
		data.unit = json['unit'].toString();
	}
	if (json['isPipe'] != null) {
		data.isPipe = json['isPipe'];
	}
	if (json['mallFee'] != null) {
		data.mallFee = json['mallFee'] is String
				? double.tryParse(json['mallFee'])
				: json['mallFee'].toDouble();
	}
	if (json['repoFee'] != null) {
		data.repoFee = json['repoFee'] is String
				? double.tryParse(json['repoFee'])
				: json['repoFee'].toDouble();
	}
	if (json['returnFee'] != null) {
		data.returnFee = json['returnFee'] is String
				? double.tryParse(json['returnFee'])
				: json['returnFee'].toDouble();
	}
	if (json['checked'] != null) {
		data.checked = json['checked'];
	}
	return data;
}

Map<String, dynamic> cartDataItemListToJson(CartDataItemList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['skuId'] = entity.skuId;
	data['spuId'] = entity.spuId;
	data['mallTitle'] = entity.mallTitle;
	data['brandId'] = entity.brandId;
	data['brandName'] = entity.brandName;
	data['skuSpec'] = entity.skuSpec;
	data['price'] = entity.price;
	data['num'] = entity.num;
	data['stock'] = entity.stock;
	data['weight'] = entity.weight;
	data['categoryName'] = entity.categoryName;
	data['unit'] = entity.unit;
	data['isPipe'] = entity.isPipe;
	data['mallFee'] = entity.mallFee;
	data['repoFee'] = entity.repoFee;
	data['returnFee'] = entity.returnFee;
	data['checked'] = entity.checked;
	return data;
}